<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box1 {
        width: 100px;
        height: 100px;
        background-color: aqua;
      }
    </style>
  </head>
  <body>
    <div class="box1">盒子</div>
    <input type="text" />
  </body>
  <script>
    const box2 = document.querySelector("div");
    box2.addEventListener("mouseenter", () => {
      console.log("鼠标进入了盒子");
    });
    box2.addEventListener("mouseleave", () => {
      console.log("鼠标离开了盒子");
    });
    const input = document.querySelector("input");
    input.addEventListener("focus", () => {
      console.log("获得焦点");
    });
    input.addEventListener("blur", () => {
      console.log("失去焦点");
    });
    input.addEventListener("keydown", () => {
      console.log("按下了键盘 keydown",)
    });
    input.addEventListener("keyup", (e) => {
      console.log("松开了键盘");
      if(e.key=='Enter'){
        console.log('按下了回车键,可以提交表单');
      }
    });
  </script>
</html>
